import storageApi from '../../../core/storage/storage';

function homeProblemListController($rootScope, $scope, homeStatsService) {
  'ngInject';

  // 问题列表
  this.getProblem = () => {
    const nowDate = new Date().getTime();
    this.hasProblemNum = false;
    const param = {
      page: 1,
      size: 3,
      mapParams: {
        orgId: $rootScope.orgId || storageApi.get('orgId'),
      },
    };
    homeStatsService
      .queryProblem(param)
      .then((res) => {
        if (res.success) {
          this.homeProblemList = res.rows.splice(0, 3);
          if (this.homeProblemList && this.homeProblemList.length > 0) {
            this.hasProblemNum = true;
            this.homeProblemList.forEach((item) => {
              if (item.overdue) {
                item.redColor = { color: '#fd5757' };
              }
            });
          } else {
            this.hasProblemNum = false;
          }
        }
      });
  };

  this.getProblem();
}

export default homeProblemListController;
